package com.lagou.work4;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

public class UserTest {

    public static void main(String[] args) {
        ServerSocket serverSocket = null;
        try {
            //1.声明服务器socket
            serverSocket = new ServerSocket(18888);
            while (true){
                System.out.println("等待客户端的连接请求...");
                //2.接受客户端链接
                Socket accept = serverSocket.accept();
                System.out.println("客户端" + accept.getInetAddress() + "连接成功！");
                //3.启动服务器线程
                new ServerThread(accept).start();
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (null != serverSocket){
                try {
                    serverSocket.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
